//
//  JBJTabBar.m
//  BaojieWeiBo02
//
//  Created by user on 15/10/5.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "JBJTabBar.h"

@implementation JBJTabBar

-(void)layoutSubviews{
    [super layoutSubviews];
    
    int index = 0;
    
    CGFloat w = [UIScreen mainScreen].bounds.size.width / 5;
    
    CGFloat h = self.bounds.size.height;
    
    CGRect frame = CGRectMake(0, 0, w, h);
    
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            view.frame = CGRectOffset(frame, index * w, 0);
            
            if (index == 1) {
                index++;
                self.composeButton.frame = CGRectOffset(frame, index * w, 0);
            }
            index++;
        }
    }
}

-(UIButton *)composeButton{
    if (!_composeButton) {
            _composeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
            [_composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
            [_composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
            [_composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
            [_composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
            [self addSubview:_composeButton];
    }
    return _composeButton;
}

//-(UIButton *)composeButton{
//    
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    
//    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
//    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
//    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
//    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
//    [self addSubview:btn];
//    return btn;
//}

@end
